
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace Iridium
{
	public static class byteFunctions
	{

		public static byte[] NumberToByte(object obj)
		{
			if (object.ReferenceEquals(obj.GetType(), typeof(int)))
			{

				return BitConverter.GetBytes((int)obj);
			}
			else if (object.ReferenceEquals(obj.GetType(), typeof(short)))
			{

				return BitConverter.GetBytes((short)obj);
			}
			else if (object.ReferenceEquals(obj.GetType(), typeof(long)))
			{

				return BitConverter.GetBytes((long)obj);
			}
			else if (object.ReferenceEquals(obj.GetType(), typeof(bool)))
			{

				return BitConverter.GetBytes((bool)obj);
			}
			else if (object.ReferenceEquals(obj.GetType(), typeof(char)))
			{
				return BitConverter.GetBytes((char)obj);
			}
			else
			{
				return null;
			}
			
		}

		public static int ByteToInteger(byte[] obj)
		{
			return BitConverter.ToInt32(obj, 0);
		}
		public static bool ByteToBoolean(byte[] obj)
		{
			return BitConverter.ToBoolean(obj, 0);
		}
		public static char ByteToChar(byte[] obj)
		{
			return BitConverter.ToChar(obj, 0);
		}
		public static short ByteToShort(byte[] obj)
		{
			return BitConverter.ToInt16(obj, 0);
		}
		public static long ByteToLong(byte[] obj)
		{
			return BitConverter.ToInt64(obj, 0);
		}
		public static uint ByteToUint(byte[] obj)
		{
			return BitConverter.ToUInt32((byte[])obj, 0);
		}
		public static byte[] StringToByte(string str)
		{
			return Encoding.Default.GetBytes(str);
		}
		public static string ByteToString(byte[] bytes)
		{
			return Encoding.Default.GetString(bytes);
		}
	}
}